//
//  CustomPresentationVc.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/6/17.
//

import UIKit

class CustomPresentationVc: UIPresentationController {

    var visualView:UIVisualEffectView!
    
    
    override func presentationTransitionWillBegin() {
        let blur = UIBlurEffect.init(style: .light)
        visualView = UIVisualEffectView.init(effect: blur)
        visualView.frame = self.containerView?.bounds ?? CGRect.zero
        visualView.alpha = 0.4
        visualView.backgroundColor = UIColor.black
        self.containerView?.addSubview(visualView)
    }
    
    override func presentationTransitionDidEnd(_ completed: Bool) {
        if completed == false {
            visualView.removeFromSuperview()
        }
    }
    
    override func dismissalTransitionWillBegin() {
        visualView.alpha = 0.0
    }
    
    override func dismissalTransitionDidEnd(_ completed: Bool) {
        if completed {
            visualView.removeFromSuperview()
        }
    }
    
    override var frameOfPresentedViewInContainerView: CGRect {
        let frameInfo = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
       
        self.presentedView?.frame = frameInfo
        
        return (self.presentedView?.frame)!
    }
    
}
